package com.gbits.websns.kernelsdk.facade.support.entity.impl;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;

import com.gbits.websns.kernelsdk.facade.support.entity.IEntity;

/**
 * @ClassName: IdentityEntity
 * @Description: 有主键的实体
 * @author: luyb
 * @date: 2014年8月6日 下午5:42:08
 */
@MappedSuperclass
public abstract class IdentityEntity implements IEntity {
	
	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid")
	@Column(name = "ID")
	private String id;// ID
	
	public String getId() {
		return id;
	}

	protected void setId(String id) {
		this.id = id;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		IdentityEntity other = (IdentityEntity) obj;
		if (this.getId() == null || other.getId() == null) {
			return false;
		} else {
			return (this.getId().equals(other.getId()));
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.getId() == null) ? 0 : this.getId().hashCode());
		return result;
	}
	
	/* (non-Javadoc)
	 * @see com.gbits.websns.kernel.common.entity.IEntity#toMap()
	 */
	public Map<Object,Object> toMap(boolean cascade) {
		Map<Object,Object> map = new HashMap<Object,Object>();
		map.put("id", this.id);
		return map;
	}
}
